<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ko">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>게시판관리</title>
	<script src="../js/jquery.js" type="text/javascript"></script>
	<script src="../js/validator.js" type="text/javascript"></script>
	<script type="text/javascript">
		//체크 박스 로직
		function checkAll(elm){
			if($(elm).attr('name') == 'bbs_write_grade'){
				$("'input:checkbox[name*='bbs_write_grade_']'").attr("checked", false);
			}else if($(elm).attr('name') == 'bbs_read_grade'){
				$("'input:checkbox[name*='bbs_read_grade_']'").attr("checked", false);
			}else if(($(elm).attr('name')).indexOf("bbs_write_grade_") != -1 ){
				$("'input:checkbox[name='bbs_write_grade']'").attr("checked", false);
			}else if(($(elm).attr('name')).indexOf("bbs_read_grade_") != -1 ){
				$("'input:checkbox[name='bbs_read_grade']'").attr("checked", false);
			}
		}
		
		//사용 비사용 체크 로직
		function display(select)
	    {
	    	if (select == 'bbs_file_y'){$('#bbs_file_yn').show(); $('input[name=bbs_file_count').val("1");} 
	    	if (select == 'bbs_file_n'){$('#bbs_file_yn').hide(); $('input[name=bbs_file_count').val("0");}
	    	if (select == 'bbs_category_y'){$('#bbs_category').show(); $('input[name=bbs_category').val("");} 
	    	if (select == 'bbs_category_n'){$('#bbs_category').hide(); $('input[name=bbs_category').val("");}
	    }
	
		//check validity
	    function reg(frm)
	    {	
			if(!checkAuth()) return false;
	    	if (!isTextValidate(frm.bbs_name, "string", 0, "게시판 이름"))				return false;
			if (!isTextValidate(frm.bbs_list_count, "number", 0, "목록 갯수"))			return false;
			if (frm.bbs_list_count.value < 8 || frm.bbs_list_count.value > 100)
			{
				alert("목록 갯수는 8~99 사이 숫자를 입력하세오");
				return false;
			}
			if (frm.bbs_file_count.value < 0 || frm.bbs_file_count.value > 10)
			{
				alert("첨부 파일 갯수는 1~9 사이 숫자를 입력하세오");
				return false;
			}
			if ($('#bbs_category_yn').attr("checked")){
		    	if (!isTextValidate(frm.bbs_category, "string", 0, "카테고리 내용"))	return false;
			}
			return makeValue();
	    }
	    
	    function makeValue(){
	    	var read = "";
	    	var write = "";
	    	
	    	$("input:checkbox[name*=bbs_read_grade]:checked").each(function(){
	    		read += $(this).val();
	    		read += "|";
	    	});
	    	$("input:checkbox[name*=bbs_write_grade]:checked").each(function(){
	    		write += $(this).val();
	    		write += "|";
	    	});
	    	
	    	read = read.slice(0,-1);
	    	write = write.slice(0,-1);
	    	$('[name=bbs_read_grade]').val(read);
	    	$('[name=bbs_write_grade]').val(write);
	    	
	    	return true;
	    }
    </script>
</head>

<body>
		<!-- 본문 영역 -->
		<div id="contents">
			<!-- 제목 및 Location 영역 -->
			<div id="location">
				<h3>게시판관리</h3>
				<div>홈 &gt; 관리메뉴 &gt; <strong>게시판관리</strong></div>
			</div>

			<!-- 본문 내용 -->
			<div id="content">
				<form name="writeFrm" method="post" action="../admin/bbsmng_proc.do" onsubmit="return reg(this);">
				<input type="hidden" name="mode" value="write" />
				<div class="ar">
					<span class="button btnProc01"><input type="submit" value="저장" /></span>
					<span class="button btnProc01"><a href="#" onclick="history.go(-1); return false;">취소</a></span>
				</div>
				<table cellspacing="0" cellpadding="0" border="0" class="tbl_type04">
					<colgroup>
						<col width="150px" />
					</colgroup>
					<tbody>
						<tr>
							<th>게시판 이름</th>
							<td><input type="text" name="bbs_name" size="20" maxlength="12" /> (12자리 이내)</td>
						</tr>
						<tr>
							<th>게시판 URL</th>
							<td><input type="text" name="bbs_url" size="50" maxlength="50" /></td>
						</tr>
						<tr>
							<th>스킨 종류</th>
							<td>
								<select title="스킨 종류 선택" name="bbs_skin">
									<option value="skin1">일반형</option>
									<option value="skin2">관리자용</option>
									<option value="skin3">사용자용</option>
									<option value="skin4">답변형</option>
									<option value="skin5">PDF형</option>
									<option value="skin6">이미지형</option>
									<option value="skin7">동영상형</option>
								</select>
							</td>
						</tr>
						<tr>
							<th>목록 갯수</th>
							<td><input type="text" name="bbs_list_count" size="3" value="20"/> (숫자 입력)</td>
						</tr>
						<tr>
							<th>답글</th>
							<td>
								<input type="radio" name="bbs_reply_yn" value="Y" checked/> 사용
								<input type="radio" name="bbs_reply_yn" value="N"/> 미사용
							</td>
						</tr>
						<tr>
							<th>댓글</th>
							<td>
								<input type="radio" name="bbs_comment_yn" value="Y" checked/> 사용
								<input type="radio" name="bbs_comment_yn" value="N"/> 미사용
							</td>
						</tr>
						<tr>
							<th>첨부파일</th>
							<td>
								<input type="radio" name="bbs_file_yn" value="Y" onclick="display('bbs_file_y')" checked/> 사용
								<input type="radio" name="bbs_file_yn" value="N" onclick="display('bbs_file_n')"/> 미사용
								<span id="bbs_file_yn" style="margin-left:20px">
									<input type="text" name="bbs_file_count" size="3" value="1"/> (숫자 입력)
								</span>
							</td>
						</tr>
						<tr>
							<th>카테고리</th>
							<td>
								<input type="radio" name="bbs_category_yn" id="bbs_category_yn" value="Y" onclick="display('bbs_category_y')" checked/> 사용
								<input type="radio" name="bbs_category_yn" value="N" onclick="display('bbs_category_n')"/> 미사용
								<span id="bbs_category" style="margin-left:20px">
									<input type="text" name="bbs_category" size="20" /> 예) 사번|소속|직책
								</span>
							</td>
						</tr>
						<tr>
							<th>게시	그룹</th>
							<td>
								<input type="radio" name="bbs_read_group_yn" value="Y" checked/> 사용
								<input type="radio" name="bbs_read_group_yn" value="N" /> 미사용
							</td>
						</tr>
						<tr>
							<th>게시	대상</th>
							<td>
								<input type="radio" name="bbs_read_user_yn" value="Y"  checked/> 사용
								<input type="radio" name="bbs_read_user_yn" value="N" /> 미사용
							</td>
						</tr>
						<tr>
							<th>읽기 권한</th>
							<td>
								<input type="checkbox" name="bbs_read_grade" value="99" onclick="checkAll(this)"checked>전체
								<input type="checkbox" name="bbs_read_grade_1" value="G0" onclick="checkAll(this)"
								style="margin-left:20px;">관리자
								<input type="checkbox" name="bbs_read_grade_2" value="G1" onclick="checkAll(this)">그룹1
								<input type="checkbox" name="bbs_read_grade_3" value="G2" onclick="checkAll(this)">그룹2
								<input type="checkbox" name="bbs_read_grade_4" value="G3" onclick="checkAll(this)">그룹3
								<input type="hidden" name="bbs_read_grade">
							</td>
						</tr>
						<tr>
							<th>쓰기 권한</th>
							<td>
								<input type="checkbox" name="bbs_write_grade" value="99" onclick="checkAll(this)" checked>전체
								<input type="checkbox" name="bbs_write_grade_1" value="G0" onclick="checkAll(this)"
								style="margin-left:20px;">관리자
								<input type="checkbox" name="bbs_write_grade_2" value="G1" onclick="checkAll(this)">그룹1
								<input type="checkbox" name="bbs_write_grade_3" value="G2" onclick="checkAll(this)">그룹2
								<input type="checkbox" name="bbs_write_grade_4" value="G3" onclick="checkAll(this)">그룹3
								<input type="hidden" name="bbs_write_grade">
							</td>
						</tr>
					</tbody>
				</table>
				</form>
			</div>
		</div>
</body>
</html>
